{include file="common/header"/}
<div class="lemo-container">
    <div class="lemo-main">
        <div class="admin-main layui-anim layui-anim-upbit">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>院系{:lang('list')}</legend>
            </fieldset>
            <blockquote class="layui-elem-quote">
<!--                <a data-href="{:url('add')}" class="layui-btn layui-btn-sm add">{:lang('add')}</a>-->
                <a class="layui-btn layui-btn-normal layui-btn-sm" onclick="openAll();">展开或折叠全部</a>
            </blockquote>
            <table class="layui-table" id="list" lay-filter="list"></table>
        </div>
    </div>
</div>

<script type="text/html" id="auth">
    <input type="checkbox" name="auth_open" data-href="{:url('ruleState')}" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="status" {{ d.auth_open == 0 ? 'checked' : '' }}>
</script>
<script type="text/html" id="status">
    <input type="checkbox" name="menu_status" data-href="{:url('ruleState')}" value="{{d.id}}" lay-skin="switch" lay-text="显示|隐藏" lay-filter="status" {{ d.menu_status == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="order">
    <input name="{{d.id}}" data-id="{{d.id}}" class="list_order layui-input" value=" {{d.sort}}" size="10"/>
</script>
<script type="text/html" id="icon">
    <span class="icon {{d.icon}}"></span>
</script>
<script type="text/html" id="action">
<!--    <a class="layui-btn layui-btn-xs" data-href="{:url('edit')}?rule_id={{d.id}}&id={{d.id}}" lay-event="edit">{:lang('edit')}</a>-->
    {{# if(d.type == 3){ }}
<!--    <a class="layui-btn layui-btn-xs layui-btn-warm"  data-href="{:url('add')}?rule_id={{d.id}}" lay-event="add">{:lang('add')}{:lang('child')}</a>-->
        {{# if(d.topic_id != null){ }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" >{{d.title_name}}</a>
        {{# }else { }}
        <a class="layui-btn layui-btn-xs layui-btn-warm"  data-href="{:url('grade_allocation')}?id={{d.id}}" lay-event="add">分配题目</a>
        {{# } }}

    {{# } }}
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs"  data-href="{:url('del')}" lay-event="del">{:lang('del')}</a>-->
</script>
<script type="text/html" id="topBtn">
    <a data-href="{:url('add')}" class="layui-btn layui-btn-sm" lay-event="add">{:lang('add')}院系</a>
</script>
{include file="common/footer"/}
<script>
    var tableIn=null, treeGrid=null,tableId='list',layer=null, Admin =null;

    layui.config({
        base: '/static/',
        version: true
    }).extend({
        treeGrid: 'plugins/layui/extend/treeGrid/treeGrid',
    }).use(['jquery','treeGrid','layer','form'], function(){
        var $=layui.jquery ,form = layui.form;
        treeGrid = layui.treeGrid;
        layer=layui.layer;
        tableIn=treeGrid.render({
            id:tableId
            ,elem: '#'+tableId
            ,idField:'id'
            ,url:'{:url("allocation")}'
            ,cellMinWidth: 100
            ,treeId:'id'//树形id字段名称
            ,treeUpId:'pid'//树形父id字段名称
            ,treeShowName:'title'//以树形式显示的字段
            ,height:'full-140'
            ,isFilter:false
            ,iconOpen:true//是否显示图标【默认显示】
            // ,isOpenDefault:true//节点默认是展开还是折叠【默认展开】
            ,cols: [[
                {field: 'id', title: '{:lang("id")}', width: 70, fixed: true, type: 'numbers'},
                {field: 'title', title: '名称', width: 200},
                {field: 'type', title: '类型', width: 200,templet: function (e) {
                        if (e.type == 1){
                            return '院系';
                        }else if (e.type == 2){
                            return '专业';
                        }else if (e.type == 3){
                            return '班级';
                        }
                    }},
                {title:'操作',width:200, toolbar: '#action',align:"center"},
            ]]
            ,page:false
        });
        treeGrid.on('tool(list)', function(obj){
            var data = obj.data;
            var url = $(this).attr('data-href');
            if(obj.event === 'del'){
                layer.confirm('是否确认删除？', function(index){
                    loading =layer.load(1, {shade: [0.1,'#fff']});
                    $.post(url?url:'delete',{ids:[data.id]},function(res){
                        layer.close(loading);
                        layer.close(index);
                        if(res.code>0){
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                });
            }else if(obj.event === 'add'){
                var iframe = layer.open({
                    type: 2,
                    content: url?url:'add',
                    area: ['800px', '600px'],
                    maxmin: true
                });
                layer.full(iframe);

            }else if(obj.event === 'edit'){

                var iframe = layer.open({
                    type: 2,
                    content: url?url:'edit',
                    area: ['600px', '800px'],
                    maxmin: true
                });
                layer.full(iframe);

            }

        });

    });
    layui.config({
        base: '/static/',
        version: true
    }).extend({
        Admin: 'admin/js/Admin',
    }).use(['Admin'], function(){
        Admin = layui.Admin
    });
    function openAll() {
        var treedata=treeGrid.getDataTreeList(tableId);
        treeGrid.treeOpenAll(tableId,!treedata[0][treeGrid.config.cols.isOpen]);
    }

</script>